Calculating percentage in a table is giving correct and wrong answers with the same query